package com.example.shiro.demo.service;

import com.example.shiro.demo.dao.RoleRepository;
import com.example.shiro.demo.dao.UserRepository;
import com.example.shiro.demo.entity.Role;
import com.example.shiro.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class RoleService {


    @Autowired
    private UserRepository userDao;

    public List<Role> findRoleByUserId(Long id) {
        Optional<User> user =  userDao.findById(id);
        if (user.isPresent()){
            return user.get().getRoles();
        }
        return null;
    }
}
